<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="stripes" uri="http://stripes.sourceforge.net/stripes.tld" %>
<jsp:useBean id="actionBean" scope="request" type="net.chowda.castcluster.action.LinkAction"/>
<html>
<head>
</head>
<body>
    <div id="linkInfo">
        <table cellpadding="5">
            <tr>
                <td valign="top">
                    <a class="imageLink" href="javascript:location.href='http://del.icio.us/post?v=4;url='+encodeURIComponent('${actionBean.url}')+';title='+encodeURIComponent('${actionBean.title}')">
                        <img src="<c:url value="/images/delicious.gif"/>" alt="bookmark with del.icio.us" title="bookmark with del.icio.us" border="0"/>
                    </a>
                    <a class="imageLink" href="javascript:location.href='http://digg.com/submit?phase=2&url='+encodeURIComponent('${actionBean.url}')+'&title='+encodeURIComponent('${actionBean.title}')<c:if test="${fn:length(actionBean.selectedText) > 0}">+'&bodytext='+encodeURIComponent('${actionBean.selectedText}')</c:if>">
                        <img src="<c:url value="/images/digg.gif"/>" alt="Digg it!" title="Digg It" border="0"/>
                    </a>
                    <a class="imageLink" target="_new" href="javascript:location.href='https://mail.google.com/mail?view=cm&tf=0&body='+ encodeURIComponent('${actionBean.url}')+ '&su='+ encodeURIComponent('${actionBean.title}')">
                        <img src="<c:url value="/images/gmail.ico"/>" alt="gmail it" title="gmail it" border="0"/>
                    </a>
                </td>
                <td>
                    <input type="hidden" id="linkVideoUrl" value="${actionBean.videoUrl}"/>
                    <span class="linkCheck">
                        URL: <a href="${actionBean.url}">${actionBean.url}</a><br/>
                    <c:if test="${actionBean.foundProvider == 'unknown'}">
                    </c:if>
                    <c:if test="${actionBean.foundProvider == 'dir'}">
                        I'm going to use the directory provider<br/>
                        I think this is a: "${actionBean.foundItemType}" with value "${actionBean.foundItem}"<br/>
                        The Cast Cluster url is: ${actionBean.videoUrl}<br/><br/>
                        Pick the playlist you would like to add this to:<br/>
                    </c:if>
                    <c:if test="${actionBean.foundProvider == 'yt'}">
                        I'm going to use the YouTube provider<br/>
                        I think this is a: "${actionBean.foundItemType}" with value "${actionBean.foundItem}"<br/>
                        The Cast Cluster url is: ${actionBean.videoUrl}<br/><br/>
                        Pick the playlist you would like to add this to:<br/>
                    </c:if>
                    <c:if test="${actionBean.foundProvider == 'gv'}">
                        I'm going to use the Google Video provider<br/>
                        I think this is a: "${actionBean.foundItemType}" with value "${actionBean.foundItem}"<br/>
                        The Cast Cluster url is: ${actionBean.videoUrl}<br/><br/>
                        Pick the playlist you would like to add this to:<br/>
                    </c:if>
                    <c:if test="${actionBean.foundProvider == 'rv'}">
                        I'm going to use the Revver provider<br/>
                        I think this is a: "${actionBean.foundItemType}" with value "${actionBean.foundItem}"<br/>
                        The Cast Cluster url is: ${actionBean.videoUrl}<br/><br/>
                        Pick the playlist you would like to add this to:<br/>
                    </c:if>
                    <c:if test="${actionBean.foundProvider == 'rss'}">
                        I found some RSS feeds:<br/>
                        <c:forEach var="title" varStatus="status" items="${actionBean.linkTitles}">
                            <span class="feedSelect">
                            ${title} - ${actionBean.linkUrls[status.index]}
                            [<a class="fakeLink useFeed" id="${actionBean.linkUrls[status.index]}" onclick="">use this feed</a>]<br/>
                            </span>
                        </c:forEach>
                        <br/>
                        Pick a feed, then pick the playlist you would like to add this to:<br/>
                    </c:if>
                    </span>
                </td>
            </tr>
        </table>
    </div>

    <jsp:include page="playlist_list.jsp"/>

<c:if test="${actionBean.foundProvider != 'unknown'}">
    <script type="text/javascript">
        $(document).ready(function() {
            $('input#addPlayListButton').bind('click', function() {
                viewVids($('input#linkVideoUrl').val());
            });
        });
        function viewVids(myVidId) {
            // show spinning cube
            $('div#viewer').html('<img src="<c:url value="/images/big_loading.gif"/>"/> Please wait... ');

            // populate preview area for current selection.
            $.get(contextPath + "ajax/Video.action", {videoUrl: myVidId}, function(data) {
                // update preview area
                $('div#viewer').html(data);
            });

            $('div.playListHeader').each(function() {
                // if we haven't already added the select link... do it now.
                if(!$('.select', $(this)).is('span')) {
                    $(this).append('<span class="select"><br/>[<span class="fakeLink">add this feed to playlist</span>]</span>');
                }

                var listId = $(this).attr('listId');
                // in case the user is changing selections we unbind.
                $('span.select', $(this)).unbind('click');

                // add cc url to playlist and reload play lists
                $('span.select', $(this)).bind('click', function() {
                    // show loading icon.
                    $(this).html('<img src="<c:url value="/images/small_loading.gif"/>"/>');
                    $.get(contextPath + "ajax/EditPlayList.action?"+"addUrl=addUrl&listId="+listId+"&videoUrl=" + myVidId, function(data) {
                        // add the new row to the playlist body
                        $('#table-' + listId).append(data);
                        // hide the link detail header
                        $('div#linkInfo').hide();
                        // hide the loading gif
                        $('span.select').html('');
                        // add the required event handlers to the new row (edit/delete/etc)
                        selectInit($('//tr[@rowId="' + listId + "_" + myVidId + '"]'));
                    });
                });
            });
        }
    </script>
</c:if>
<c:if test="${actionBean.foundProvider == 'rss'}">
    <script type="text/javascript">
        $('a.useFeed').bind('click', function() {
            $('span.feedSelect').css('background-color', 'white');
            $(this).parent('span.feedSelect').css('background-color', 'lightblue');
            $('input#linkVideoUrl').val('rss|url|' + this.id);
            viewVids('rss|url|' + this.id);
        });
    </script>
</c:if>
<c:if test="${actionBean.foundProvider == 'yt' || actionBean.foundProvider == 'gv' || actionBean.foundProvider == 'rv' || actionBean.foundProvider == 'dir'}">
    <script type="text/javascript">
        viewVids($('input#linkVideoUrl').val());
    </script>
</c:if>
</body>
</html>
